<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>014父子组件之间数据传递</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="root">
    <!-- 父组件通过属性count向子组件<counter>传递了一个 名字叫count的数据 -->
    <counter :count="one" @change="handleIncrease"></counter>
    <counter :count="two" @change="handleIncrease"></counter>
    <div>{{total}}</div>
  </div>
  <script>
    var vm = new Vue({
      el: "#root",
      data: {
        one: 1,
        two: 3,
        total: 4
      },
      components: {
        "counter": {
          props: ["count"],
          data:function() {
            return {
              number: this.count
            }
          },
          template: "<div @click='handleClick'>{{number}}</div>",
          methods: {
            handleClick: function() {
              this.number++;
              this.$emit("change",1);
            }
          },
        }
      },
      methods: {
        handleIncrease: function(step) {
          this.total += step;
        }
      }
    })
  </script>
</body>

</html>